import commonConstant from "../common/commonConstant.js";
import {globalData} from "../globalData/globalData.js";
import {Game, onWSAnimationInfo, onWSGameDataUpdate, onWSStartGame, onWSTurnChange} from "../game/gaming.js";

export const onWSMessage = (res) => {
    // console.log("服务器返回的信息: " ,res);
    let _res = JSON.parse(res.data)
    if(_res.code===commonConstant.errorCode){
        console.log('发生错误');
        return
    }
    if(_res.cmd === commonConstant.CMD_UPDATE_ROOM_INFO){
        globalData.room.updateRoomInfo(_res.data)
    }else if(_res.cmd === commonConstant.CMD_START_GAME){
        new Game()
        onWSStartGame(_res.data)

    }else if(_res.cmd === commonConstant.CMD_UPDATE_GAME_DATA){
        onWSGameDataUpdate(_res.data)

    }else if(_res.cmd === commonConstant.CMD_UPDATE_ANIMATION_INFO){
        onWSAnimationInfo(_res.data)

    }else if(_res.cmd === commonConstant.CMD_GAME_TURN_CHANGE){
        onWSTurnChange(_res.data)

    }
}